/*
 * Copyright (C) 2024-2025 Deepin Technology Co., Ltd.
 *
 * Author:     zhangbingyi <zhangbingyi@uniontech.com>
 *
 * Maintainer: zhangbingyi <zhangbingyi@uniontech.com>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
#include "usbinfodialog.h"

//#include <DTitlebar>

#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QDebug>


UsbInfoDialog::UsbInfoDialog(QWidget *parent)
    : QFrame(parent)
//    , m_blurEffect(nullptr)
    , m_mainWidgt(nullptr)
    , m_mainLayout(nullptr)
{
    Qt::WindowFlags flags = windowFlags();
    flags |= Qt::Dialog;
    setWindowFlags(flags);
    setWindowFlags(Qt::Dialog);
    setWindowModality(Qt::ApplicationModal);
    setAttribute(Qt::WA_TranslucentBackground);

//    m_blurEffect = new DBlurEffectWidget(this);
//    m_blurEffect->setBlendMode(DBlurEffectWidget::BehindWindowBlend);

//    m_blurEffect->resize(size());
//    m_blurEffect->lower();

//    //close button
//    QHBoxLayout *titleBarLayout = new QHBoxLayout(this);
//    titleBarLayout->setContentsMargins(0, 0, 0, 0);
//    DTitlebar *titleBar = new DTitlebar(this);
//    titleBar->setBackgroundTransparent(true);
//    titleBar->setTitle("");
//    titleBar->setMenuVisible(false);
//    titleBarLayout->addWidget(titleBar, 0, Qt::AlignRight | Qt::AlignTop);

    initUI();
}

void UsbInfoDialog::initUI()
{
    m_mainWidgt = new QWidget(this);
    m_mainWidgt->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
    m_mainWidgt->move(0, 50);
    m_mainWidgt->resize(size().width(), size().height() - 50);
    m_mainLayout = new QVBoxLayout;
    m_mainLayout->setContentsMargins(10, 0, 10, 10);
    m_mainLayout->setSpacing(0);
    m_mainWidgt->setLayout(m_mainLayout);
}

void UsbInfoDialog::resizeEvent(QResizeEvent *event)
{
    Q_UNUSED(event);

    m_mainWidgt->resize(size().width(), m_mainLayout->sizeHint().height());
    resize(size().width(), m_mainLayout->sizeHint().height() + 50);
//    m_blurEffect->resize(size());
}

void UsbInfoDialog::closeEvent(QCloseEvent *event)
{
    Q_UNUSED(event);
    this->deleteLater();
}

void UsbInfoDialog::paintEvent(QPaintEvent *event)
{
    Q_UNUSED(event);

    m_mainWidgt->resize(size().width(), m_mainLayout->sizeHint().height());
    resize(size().width(), m_mainLayout->sizeHint().height() + 50);
//    m_blurEffect->resize(size());
}
